package com.easylinkin.linkappapi.device.controller;

import com.easylinkin.linkappapi.device.entity.Device;
import com.easylinkin.linkappapi.device.entity.vo.CountByDffAttrVo;
import com.easylinkin.linkappapi.device.service.DeviceService;
import com.easylinkin.linkappapi.device.vo.DeviceStatisticsVo;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import com.easylinkin.linkappapi.security.entity.LinkappUser;
import com.easylinkin.linkappapi.openapi.service.OpenApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2020-04-14
 */
@RestController
@Api(value = "设备统计类控制器", tags = {"设备统计控制器"})
@RequestMapping("/device/statistics")
public class DeviceStatisticsController {

    @Resource
    private DeviceService service;
    @Resource
    private OpenApiService openApiService;
    @Resource
    private LinkappUserContextProducer linkappUserContextProducer;

    /**
     * 按类型统计在线计数,各类别的总数多少在线数多少
     *
     * @param device 查询实体
     * @return
     */
    @ApiOperation("按类型统计在线计数,各类别的总数多少在线数多少")
    @PostMapping("/statisticCountWithOnlineByType")
    public RestMessage statisticCountWithOnlineByType(@RequestBody Device device) {
        Assert.notNull(device, "参数为空");
        return RestBuilders.successBuilder().data(service.statisticCountWithOnlineByType(device)).build();
    }
    /**
     * 按类型统计在线计数,各类别的总数多少在线数多少
     *
     * @param countByDffAttrVo 查询实体
     * @return
     */
    @ApiOperation("按类型统计在线计数,各类别的总数多少在线数多少")
    @PostMapping("/statisticCountWithDffAttr")
    public RestMessage statisticCountWithDffAttr(@RequestBody CountByDffAttrVo countByDffAttrVo) {
        Assert.notNull(countByDffAttrVo, "countByDffAttrVo 参数为空");
        return RestBuilders.successBuilder().data(service.statisticCountWithDffAttr(countByDffAttrVo)).build();
    }

    @ApiOperation("设备统计")
    @GetMapping("/statistics")
    public RestMessage statistics() {
        return RestBuilders.successBuilder().data(service.getDeviceStatisticsByTenantId()).build();
    }
}
